include('shared.lua')

function ENT:Draw()
	self.Entity:DrawModel()
end

local PANEL = {}

local slidervalue=""

function PANEL:DoClick()
	local panel2=self:GetParent()
	local val=panel2.Distance:GetValue()
	LocalPlayer():ConCommand("dodialrings "..tostring(val).." "..panel2.TextEntry:GetValue())
	panel2:SetVisible(false); -- Instead of deleting this panel, we make it invisible (better) @aVoN
	panel2:SetKeyBoardInputEnabled(false);
	panel2:SetMouseInputEnabled(false);
	--panel2:Remove()
end

vgui.Register( "RingDialButton", PANEL, "Button" )

local PANEL = {}
local function ChangeDistance( panel, message, param1, param2 )
	if (message != "SliderMoved") then return end
	local str=string.format( "%.1f", param1 )
	panel:GetParent().L2:SetText(str)
	slidervalue=str
end

function PANEL:Init()
	self:SetSize(400,500)
	self:SetName( "Dial" )
 	self.TextEntry = vgui.Create( "TextEntry", self )
 	self.TextEntry:SetText("")

 	self.L1 = vgui.Create( "Label", self )
 	self.L1:SetText("Enter destination address (one word!) and maximum ring distance (this will set BOTH ENDS) or just hit dial for closest.")

 	self.Button = vgui.Create( "RingDialButton", self)
	self.Button:SetText("Dial")

	self.Distance=vgui.Create( "CheckButton", self)
	self.Distance:SetToolTip("If checked, rings will seek ground within 1024 units. Else they'll just go to head height.")
	self.Distance:SetText("Find range?")
end

function PANEL:Paint()
	draw.RoundedBox( 10, 0, 0, self:GetWide(), self:GetTall() , Color(16,16,16,160) )
	return true
end

function PANEL:PerformLayout()

 	self:SetSize( 700, 150 )

	self.Button:SetPos(10,90)

 	self.TextEntry:SetSize( 400, self.TextEntry:GetTall() )
 	self.TextEntry:SetPos( 10, 40 )

 	self.L1:SetPos( 10, 15 )
 	self.L1:SetSize( 700, 30 )

 	self.Distance:SetPos( 10, 70 )
 	self.Distance:SetSize( 300, 15 )

end

vgui.Register( "RingDestinationEntry", PANEL, "Frame" )
local Window
function RingTransporterShowWindow(um)
	Window = Window or vgui.Create( "RingDestinationEntry" )
	Window:SetKeyBoardInputEnabled( true )
	Window:SetMouseInputEnabled( true )
	Window:SetPos( (ScrW()/2 - 350) / 2, ScrH()/2 - 75 )
	Window:SetVisible( true )
end
usermessage.Hook("RingTransporterShowWindow", RingTransporterShowWindow)